function eyelid_points = detect_eyelid(I, center, radius, debug)
    % Find the edge on the left part of the eye
    cx = center(1);
    cy = center(2);
    
    r = I(:,:,2)+I(:,:,3);
    upper_points = zeros(size(r));
    lower_points = zeros(size(r));
    gfilter = fspecial('gaussian',10,1);
    r = imfilter(r,gfilter);
    
    lr = 5:cx;
    rr = cx:size(r,2)-5;
    leftpart = r(:,lr);
    rightpart = r(:,rr);
    iris_location = [center radius];
    
    upper_left = get_eyelid(iris_location,leftpart,10:2:80,true,debug);
    lower_left = get_eyelid(iris_location,leftpart,-90:2:-60,false,debug);
    upper_right= get_eyelid(iris_location,rightpart,-80:2:-20,true,debug);
    lower_right = get_eyelid(iris_location,rightpart,50:2:89,false,debug);
    
    upper_points(:,lr) = upper_points(:,lr) +  upper_left;
    upper_points(:,rr) = upper_points(:,rr) + upper_right;
    
    lower_points(:,lr) = lower_points(:,lr) +  lower_left;
    lower_points(:,rr) = lower_points(:,rr) + lower_right;
    %lower_points(cy+radius,cx-5:cx+5) = 1;
    
    % Pick 6 x-indeces
    points = cx-2*radius:radius:cx+2*radius;
    [y,x] = find(upper_points);
    f = polyfit(x,y,3);
    upper_curve = polyval(f,1:size(r,2));
    upper_points = polyval(f,points);
    
    [y,x] = find(lower_points);
    f = polyfit(x,y,3);
    lower_curve = polyval(f,1:size(r,2));
    lower_points = polyval(f,points);
    
    eyelid_points = [points' upper_points'; points' lower_points';];
    
    [px, py] = circlepoints(radius);
    h = figure(20);
    close(h);
    
    if debug
        %close all;
        %figure(1); imshow(r); hold on; plot(points,upper_points,'ro'); plot(upper_curve); plot(points,lower_points,'ro'); plot(lower_curve); plot(px+cx,py+cy);
        %figure(2); imshow(upper_points); hold on; plot(upper_curve);
        %figure(3); imshow(lower_points); hold on; plot(lower_curve);
    end
    
end